Your goal is to create this plot.

  1. Download https://michaelgastner.com/DAVisR_data/life_quality.csv.

  2. plot a scatterplot

  • x-axis: gdp_per_capita
  • y-axis: life_expectancy
  • mode: markers
  1. set colors by continents
  • make sure you have two separate arguments

  • one to specify which column to use for coloring

  • the other to specify the colors

  • You may use this pallete for colouring continents.

    colors <- c("#e41a1c", '#377eb8', '#4daf4a', '#984ea3', '#ff7f00')
  1. set size
  • size by population

  • The default for the parameter fill is None and it seems to cause an error.

  • You will see the following warning “Warning: line.width does not currently support multiple values”.

  • you may consider adding the following argument in plot_ly(); this code assigns an empty string to fill.

    fill = ~'',
  • Unfortunately, as of today, plotly does not support the size legend. However, some people seem to have found a way around by creating a new plot just for legend and combine it with the original bubble chart using subplot function. You can try it once you are done with the rest of exercises.

  1. assign texts to each point
  • show country name, gdp, life expectancy, and population
  • remember to put line breaks
  • for gdp and life expectancy, round the numbers to 2 digits
  1. add labels
  • add an appropriate title

  • add an appropriate legend

  • add an appropriate x and y axis

  • for adding the source, you may consider using the code below:

    annotations = list(
      x = 1.2, y = -0.1,
      text = "Source: World Bank",
      showarrow = F, xref = "paper", yref = "paper",
      xanchor = "right", yanchor = "auto", xshift = 0, yshift = 0,
      font = list(size = 12)
    )
  1. fine-tune, complete the plot
  • make sure the x-axis is log-transformed
  • make sure the sizes of the symbol in the legend are constant.
  • improve the plot, if you would like.

Thank you!